package com.czh.springboot04.service.serviceimpl;

import com.czh.springboot04.entity.Course;
import com.czh.springboot04.mapper.CourseMapper;
import com.czh.springboot04.service.CourseService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CourseServiceImpl implements CourseService {
    @Autowired
    private CourseMapper courseMapper;


    @Override
    public PageInfo<Course> findAll(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Course> course = courseMapper.selectAll();
        PageInfo<Course> coursePageInfo = new PageInfo<>(course);
        return coursePageInfo;
    }

    @Override
    public int addCourse(Course course) {
        int i = courseMapper.addCourse(course);
        return i;
    }

    @Override
    public int updateCourse(Course course) {
        int i = courseMapper.updateCourse(course);
        return i;
    }

    @Override
    public int deleteCourse(int id) {
        int i = courseMapper.deleteCourse(id);
        return i;
    }

    @Override
    public PageInfo<Course> findCourseById(int id, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Course> course = courseMapper.findCourseById(id);
        PageInfo<Course> coursePageInfo = new PageInfo<>(course);
        return coursePageInfo;
    }

    @Override
    public PageInfo<Course> selectCourseByName(String courseName, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Course> course = courseMapper.selectCourseByName(courseName);
        PageInfo<Course> coursePageInfo = new PageInfo<>(course);
        return coursePageInfo;
    }

    @Override
    public PageInfo<Course> selectCourseByPriceAsc(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Course> course = courseMapper.selectCourseByPriceAsc();
        PageInfo<Course> coursePageInfo = new PageInfo<>(course);
        return coursePageInfo;
    }

    @Override
    public PageInfo<Course> selectCourseByPriceDesc(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Course> course = courseMapper.selectCourseByPriceDesc();
        PageInfo<Course> coursePageInfo = new PageInfo<>(course);
        return coursePageInfo;
    }

    @Override
    public PageInfo<Course> selectCourseByPrice(double min, double max, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Course> course = courseMapper.selectCourseByPrice(min,max);
        PageInfo<Course> coursePageInfo = new PageInfo<>(course);
        return coursePageInfo;
    }

    @Override
    public PageInfo<Course> selectCourseByCollection(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Course> course = courseMapper.selectCourseByCollection();
        PageInfo<Course> coursePageInfo = new PageInfo<>(course);
        return coursePageInfo;
    }

    @Override
    public PageInfo<Course> selectCourseByType(int pageNum, int pageSize, int typeId) {
        PageHelper.startPage(pageNum,pageSize);
        List<Course> course = courseMapper.selectCourseByType(typeId);
        PageInfo<Course> coursePageInfo = new PageInfo<>(course);
        return coursePageInfo;
    }

    @Override
    public PageInfo<Course> selectCourseByTypeAndCollection(int pageNum, int pageSize, int typeId) {
        PageHelper.startPage(pageNum,pageSize);
        List<Course> course = courseMapper.selectCourseByTypeAndCollection(typeId);
        PageInfo<Course> coursePageInfo = new PageInfo<>(course);
        return coursePageInfo;
    }

    @Override
    public PageInfo<Course> selectCourseByTypeAndPriceAsc(int pageNum, int pageSize, int typeId) {
        PageHelper.startPage(pageNum,pageSize);
        List<Course> course = courseMapper.selectCourseByTypeAndPriceAsc(typeId);
        PageInfo<Course> coursePageInfo = new PageInfo<>(course);
        return coursePageInfo;
    }

    @Override
    public PageInfo<Course> selectCourseByTypeAndPriceDesc(int pageNum, int pageSize, int typeId) {
        PageHelper.startPage(pageNum,pageSize);
        List<Course> course = courseMapper.selectCourseByTypeAndPriceDesc(typeId);
        PageInfo<Course> coursePageInfo = new PageInfo<>(course);
        return coursePageInfo;
    }

    @Override
    public PageInfo<Course> selectCourseByTypeAndPrice(int pageNum, int pageSize, double min, double max, int typeId) {
        PageHelper.startPage(pageNum,pageSize);
        List<Course> course = courseMapper.selectCourseByTypeAndPrice(min,max,typeId);
        PageInfo<Course> coursePageInfo = new PageInfo<>(course);
        return coursePageInfo;
    }

    @Override
    public Course findCourseByCourseId(int id) {
        Course course = courseMapper.findCourseByCourseId(id);
        return course;
    }

}
